<template>
    <div class="data-config-container">
        <el-tabs v-model="activeTab" type="border-card" class="config-tabs">
            <!-- 模块1: 绿电供应 -->
            <el-tab-pane label="绿电供应" name="greenPower">
                <module1 ref="module1Ref"></module1>

            </el-tab-pane>

            <!-- 模块2: 共享出行 -->
            <!-- <el-tab-pane label="共享出行" name="sharedTravel">
                <module2 ref="module2Ref"></module2>
            </el-tab-pane> -->

            <!-- 模块3: 绿电环保配置 -->
            <el-tab-pane label="数据统计" name="database">
                <module3 ref="module3Ref"></module3>

            </el-tab-pane>

            <!-- 模块4: 能源服务配置 -->
            <el-tab-pane label="能源数据配置" name="monitor">
                <module4 ref="module4Ref"></module4>

            </el-tab-pane>

            <!-- 模块5: 地图标点配置 -->
            <el-tab-pane label="地图标点配置" name="security">
                <module8 ref="module8Ref"></module8>
            </el-tab-pane>

            <!-- 模块6: 共享换电 -->
            <el-tab-pane label="共享换电" name="sharedSwap">
                <module6 ref="module6Ref"></module6>
            </el-tab-pane>

            <!-- 模块7: 配送服务配置 -->
            <!-- <el-tab-pane label="共享运力" name="sharedCapacity">
                <module7 ref="module7Ref"></module7>

            </el-tab-pane> -->
        </el-tabs>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Location } from '@element-plus/icons-vue'
import { updateDataClassify, getDataClassifyDetail } from '@/api/port'

import module1 from '@/components/home/module1.vue'
import module2 from '@/components/home/module2.vue'
import module3 from '@/components/home/module3.vue'
import module4 from '@/components/home/module4.vue'
import module5 from '@/components/home/module5.vue'
import module6 from '@/components/home/module6.vue'
import module7 from '@/components/home/module7.vue'
import module8 from '@/components/home/module8.vue'
// 暂时注释掉未找到的模块导入




const module1Ref = ref<InstanceType<typeof module1>>()
const module2Ref = ref<InstanceType<typeof module2>>()
const module3Ref = ref<InstanceType<typeof module3>>()
const module4Ref = ref<InstanceType<typeof module4>>()
const module5Ref = ref<InstanceType<typeof module5>>()
const module6Ref = ref<InstanceType<typeof module6>>()
const module7Ref = ref<InstanceType<typeof module7>>()
const module8Ref = ref<InstanceType<typeof module8>>()

const moduleDetail = ref({
    module1: {},
    module2: {},
    module3: {},
    module4: {},
    module5: {},
    module6: {},
    module7: {},
    module8: {},

})
const getDetail = async () => {
    const res = await getDataClassifyDetail({
        id: 1
    })
    console.log(res)
    moduleDetail.value = res
    console.log(moduleDetail.value)
    module1Ref.value?.init(moduleDetail.value.module1)
    module2Ref.value?.init(moduleDetail.value.module2)
    module3Ref.value?.init(moduleDetail.value.module3)
    module4Ref.value?.init(moduleDetail.value.module4)
    module5Ref.value?.init(moduleDetail.value.module5)
    module6Ref.value?.init(moduleDetail.value.module6)
    module7Ref.value?.init(moduleDetail.value.module7)

    let obj = {
        module5: moduleDetail.value.module5,
        module8: moduleDetail.value.module8
    }

    module8Ref.value?.init(obj)
}
onMounted(() => {
    getDetail()

})

// 当前激活的标签页
const activeTab = ref('greenPower')
</script>

<style >
.data-config-container {
    padding: 20px;
    background: #f5f7fa;
    min-height: 100vh;
}

.config-tabs {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.tab-content {
    padding: 30px;
}

.config-form {
    max-width: 1200px;
}

.save-button-container {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e4e7ed;
}

.save-button-container .el-button {
    padding: 12px 40px;
    font-size: 14px;
}

:deep(.el-tabs__header) {
    margin: 0;
}

:deep(.el-tabs__nav-wrap) {
    padding: 0 20px;
}

:deep(.el-tabs__item) {
    padding: 0 20px;
    font-size: 14px;
    font-weight: 500;
}

:deep(.el-tabs__content) {
    padding: 0;
}

:deep(.el-form-item) {
    margin-bottom: 20px;
}

:deep(.el-input) {
    width: 100%;
}

:deep(.el-select) {
    width: 100%;
}

/* 24小时数据配置样式 */
.day-selector {
    margin-bottom: 24px;
    text-align: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.2);
}

.day-radio-group {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    padding: 6px;
    backdrop-filter: blur(10px);
}

.day-radio-group :deep(.el-radio-button__inner) {
    border: none;
    background: transparent;
    color: #666;
    font-weight: 500;
    padding: 10px 20px;
    transition: all 0.3s ease;
}

.day-radio-group :deep(.el-radio-button__original-radio:checked + .el-radio-button__inner) {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.hourly-grid {
    border: 1px solid #e4e7ed;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.grid-header {
    display: grid;
    grid-template-columns: 140px 1fr 100px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 16px 20px;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #dee2e6;
    font-size: 14px;
}

.grid-content {
    max-height: 450px;
    overflow-y: auto;
}

.grid-content::-webkit-scrollbar {
    width: 6px;
}

.grid-content::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.grid-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.grid-content::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.grid-row {
    display: grid;
    grid-template-columns: 140px 1fr 100px;
    padding: 12px 20px;
    border-bottom: 1px solid #f0f2f5;
    align-items: center;
    transition: all 0.2s ease;
}

.grid-row:hover {
    background: linear-gradient(135deg, #f8f9ff 0%, #f0f4ff 100%);
    transform: translateX(2px);
}

.grid-row:last-child {
    border-bottom: none;
}

.time-cell {
    display: flex;
    align-items: center;
}

.time-cell .el-tag {
    font-weight: 600;
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 20px;
}

.value-cell {
    padding: 0 16px;
}

.value-cell :deep(.el-input-number) {
    width: 120px;
}

.value-cell :deep(.el-input__inner) {
    border-radius: 6px;
    border: 1px solid #dcdfe6;
    transition: all 0.3s ease;
    font-size: 13px;
    height: 32px;
}

.value-cell :deep(.el-input__inner:focus) {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.value-cell :deep(.el-input-number__decrease),
.value-cell :deep(.el-input-number__increase) {
    width: 24px;
    height: 16px;
    font-size: 12px;
}

.action-cell {
    display: flex;
    justify-content: center;
}

.reset-btn {
    color: #909399;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.reset-btn:hover {
    color: #409eff;
    background: rgba(64, 158, 255, 0.1);
}

.batch-operations {
    margin-bottom: 24px;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    text-align: center;
    border: 1px solid #dee2e6;
}

.batch-operations :deep(.el-button) {
    margin: 0 8px;
    border-radius: 20px;
    padding: 8px 20px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.batch-operations :deep(.el-button:hover) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 地图标点配置样式 */
.map-points-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 16px 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.map-points-header h3 {
    margin: 0;
    color: #495057;
    font-size: 16px;
    font-weight: 600;
}

:deep(.el-table) {
    border-radius: 8px;
    overflow: hidden;
}

:deep(.el-table th) {
    background: #f8f9fa;
    color: #495057;
    font-weight: 600;
}

:deep(.el-dialog__header) {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    margin: 0;
}

:deep(.el-dialog__title) {
    color: white;
    font-weight: 600;
}

:deep(.el-dialog__body) {
    padding: 30px;
}

/* 地图标点弹窗样式 */
.point-dialog .dialog-content {
    display: flex;
    gap: 30px;
}

.point-dialog .form-section {
    flex: 1;
    min-width: 300px;
}

.point-dialog .map-section {
    flex: 1;
    min-width: 300px;
}

.point-dialog h4 {
    margin: 0 0 20px 0;
    color: #333;
    font-size: 16px;
    font-weight: 600;
    border-bottom: 2px solid #e9ecef;
    padding-bottom: 10px;
}

.tmap-container {
    height: 300px;
    background: #f5f7fa;
    border: 1px solid #e4e7ed;
    border-radius: 8px;
    overflow: hidden;
}

.map-actions {
    margin-top: 10px;
    display: flex;
    gap: 10px;
}

.map-placeholder {
    height: 300px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.grid-row {
    display: grid;
    grid-template-columns: 140px 1fr 100px;
    padding: 12px 20px;
    border-bottom: 1px solid #f0f2f5;
    align-items: center;
    transition: all 0.2s ease;
}

.grid-row:hover {
    background: linear-gradient(135deg, #f8f9ff 0%, #f0f4ff 100%);
    transform: translateX(2px);
}

.grid-row:last-child {
    border-bottom: none;
}

.time-cell {
    display: flex;
    align-items: center;
}

.time-cell .el-tag {
    font-weight: 600;
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 20px;
}

.value-cell {
    padding: 0 16px;
}

.value-cell :deep(.el-input-number) {
    width: 120px;
}

.value-cell :deep(.el-input__inner) {
    border-radius: 6px;
    border: 1px solid #dcdfe6;
    transition: all 0.3s ease;
    font-size: 13px;
    height: 32px;
}

.value-cell :deep(.el-input__inner:focus) {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.value-cell :deep(.el-input-number__decrease),
.value-cell :deep(.el-input-number__increase) {
    width: 24px;
    height: 16px;
    font-size: 12px;
}

.action-cell {
    display: flex;
    justify-content: center;
}

.reset-btn {
    color: #909399;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.reset-btn:hover {
    color: #409eff;
    background: rgba(64, 158, 255, 0.1);
}

.batch-operations {
    margin-bottom: 24px;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    text-align: center;
    border: 1px solid #dee2e6;
}

.batch-operations :deep(.el-button) {
    margin: 0 8px;
    border-radius: 20px;
    padding: 8px 20px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.batch-operations :deep(.el-button:hover) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 地图标点配置样式 */
.map-points-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 16px 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.map-points-header h3 {
    margin: 0;
    color: #495057;
    font-size: 16px;
    font-weight: 600;
}

:deep(.el-table) {
    border-radius: 8px;
    overflow: hidden;
}

:deep(.el-table th) {
    background: #f8f9fa;
    color: #495057;
    font-weight: 600;
}

:deep(.el-dialog__header) {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    margin: 0;
}

:deep(.el-dialog__title) {
    color: white;
    font-weight: 600;
}

:deep(.el-dialog__body) {
    padding: 30px;
}

/* 地图标点弹窗样式 */
.point-dialog .dialog-content {
    display: flex;
    gap: 30px;
}

.point-dialog .form-section {
    flex: 1;
    min-width: 300px;
}

.point-dialog .map-section {
    flex: 1;
    min-width: 300px;
}

.point-dialog h4 {
    margin: 0 0 20px 0;
    color: #333;
    font-size: 16px;
    font-weight: 600;
    border-bottom: 2px solid #e9ecef;
    padding-bottom: 10px;
}

.map-placeholder {
    height: 300px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.map-placeholder::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="%23dee2e6" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>') repeat;
    opacity: 0.3;
}

.map-tips {
    text-align: center;
    z-index: 1;
    position: relative;
}

.map-tips .el-icon {
    font-size: 48px;
    color: #6c757d;
    margin-bottom: 16px;
}

.map-tips p {
    margin: 8px 0;
    color: #6c757d;
    font-size: 14px;
}

.map-tips .el-button {
    margin-top: 16px;
}

:deep(.point-dialog .el-dialog__header) {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
}

:deep(.point-dialog .el-form-item__label) {
    font-weight: 600;
    color: #495057;
}

:deep(.point-dialog .el-input__wrapper) {
    border-radius: 6px;
}

:deep(.point-dialog .el-select .el-input__wrapper) {
    border-radius: 6px;
}

/* 图表数据配置样式 */
.chart-data-section {
    margin-top: 30px;
    padding: 20px;
    border: 1px solid #e4e7ed;
    border-radius: 8px;
    background-color: #fafafa;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e4e7ed;
}

.section-header h4 {
    margin: 0;
    color: #303133;
    font-size: 16px;
    font-weight: 600;
}

.chart-data-list {
    min-height: 100px;
    max-height: 300px;
    overflow-y: auto;
}

.chart-item {
    margin-bottom: 15px;
    padding: 15px;
    background: white;
    border: 1px solid #e4e7ed;
    border-radius: 6px;
    transition: all 0.3s;
}

.chart-item:hover {
    border-color: #409eff;
    box-shadow: 0 2px 8px rgba(64, 158, 255, 0.1);
}

.chart-item-content {
    display: flex;
    align-items: center;
    gap: 20px;
}

.chart-item-field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-item-field label {
    min-width: 70px;
    font-size: 14px;
    color: #606266;
    font-weight: 500;
}

.chart-item-actions {
    margin-left: auto;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #909399;
}

.empty-state p {
    margin: 0;
    font-size: 14px;
}

/* 滚动条样式 */
.chart-data-list::-webkit-scrollbar {
    width: 6px;
}

.chart-data-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chart-data-list::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chart-data-list::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}
</style>